package com.lins.common.mp.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author yuxiaolin
 * @title: FillMetaObjectHandler
 * @projectName lins
 * @description:  创建时间，创建者
 * @date 2021/12/13 3:30 下午
 */

@Slf4j
@Component
public class FillMetaObjectHandler implements MetaObjectHandler {

    private String accountName;

    private String tenantCode;


    public FillMetaObjectHandler(FillMetaService fillMetaService)
    {
        this.accountName = fillMetaService.getAccountName();
        this.tenantCode = fillMetaService.getTenantCode();
    }

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("插入，添加睡哪或者插入时间....");

        this.strictInsertFill(metaObject, "createdTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updatedTime", Date.class, new Date());
        this.strictInsertFill(metaObject,"tenantCode",String.class,tenantCode);
        this.strictInsertFill(metaObject,"updatedBy",String.class,accountName);
        this.strictInsertFill(metaObject,"createdBy",String.class,accountName);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("插入，添加睡哪或者插入时间....");
        this.strictUpdateFill(metaObject, "updatedTime", Date.class, new Date());
        this.strictInsertFill(metaObject,"updatedBy",String.class,accountName);

    }
}
